package com.sdkj.dao.base;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;

import com.sdkj.Entity.BaseEntity;

/**
 * dao 基类
 * @author sdkj
 *
 * @param <T> PO
 */
public interface IBaseDao<T> {

	/**
	 * 保存对象
	 * @author sdkj
	 *
	 * @param o
	 * @return id
	 * @throws SQLException
	 */
	public Serializable save(T o) throws SQLException  ;
	/**
	 * 批量保存
	 * @author sdkj
	 *
	 * @param list
	 * @throws SQLException
	 */
	public void saveBatch(List<? extends BaseEntity> list) throws SQLException;

	/**
	 * 删除对象 
	 * @author sdkj
	 *
	 * @param o
	 * @throws SQLException
	 */
	public void delete(T o) throws SQLException ;

	/**
	 * 保存或者修改对象
	 * @author sdkj
	 *
	 * @param o
	 * @throws SQLException
	 */
	public void saveOrUpdate(T o) throws SQLException ;

	/**
	 * 修改一个对象
	 * @author sdkj
	 *
	 * @param o
	 * @throws SQLException
	 */
	public void update(T o) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param c
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public T findById(Class<?> c, Serializable id) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public T getByHql(String hql) throws HibernateException, SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @param params
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public T getByHql(String hql, Map<String, Object> params) throws HibernateException, SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @return
	 * @throws SQLException
	 */
	public List<T> findByHql(String hql) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public List<T> findByHql(String hql, Map<String, Object> params) throws SQLException ;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @param params
	 * @param page
	 * @param rows
	 * @return
	 * @throws SQLException
	 */
	public List<T> findByHql(String hql, Map<String, Object> params, int page, int rows) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @param clazz
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<?> findBySqlToBean(String sql, Map<String, Object> params, int page, int rows,Class<?> clazz) throws HibernateException, SQLException ;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql) throws HibernateException, SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param page
	 * @param rows
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, int page, int rows) throws HibernateException, SQLException;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, Map<String, Object> params) throws HibernateException, SQLException ;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<Map<String, ?>> findBySqlToMap(String sql, Map<String, Object> params, int page, int rows) throws HibernateException, SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @return
	 * @throws SQLException
	 */
	public int executeHql(String hql) throws SQLException;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public int executeHql(String hql, Map<String, Object> params) throws SQLException;
	
	/**
	 * 执行 sql 封装 成 bean 
	 *  不一致的字段使用 as 别名
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @param page
	 * @param rows
	 * @param clazz
	 * @return
	 * @throws HibernateException
	 * @throws SQLException
	 */
	public List<T> findToBean(String sql,Map<String,Object>params,int page,int rows,Class<T> clazz) throws HibernateException, SQLException;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	public int getCountBySql(String sql) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public int getCountBySql(String sql, Map<String,Object> params) throws SQLException ;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	public int executeSql(String sql) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param sql
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public int executeSql(String sql, Map<String, Object> params) throws SQLException ;
	
	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @return
	 * @throws SQLException
	 */
	public int getCountByHql(String hql) throws SQLException ;

	/**
	 * 
	 * @author sdkj
	 *
	 * @param hql
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public int getCountByHql(String hql, Map<String, Object> params) throws SQLException ;
	

	

}
